//
//  AboutViewController.m
//  MixedPlayerSdkDemo_Dev
//
//  Created by Gikki Ares on 2022/12/19.
//

#import "JsAboutViewController.h"
#import <JsUtilitySdk/JsLogoView.h>
#import <JsUtilitySdk/JsUtilitySdk.h>
#import "JsBundleManager.h"
@interface JsAboutViewController (){
	int mi_updateCount;
}
@property (weak, nonatomic) IBOutlet JsLogoView *mLogoView;

@end

@implementation JsAboutViewController


- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
	_vm = [JsAboutViewControllerVm new];
	if(!nibNameOrNil) {
		nibNameOrNil = NSStringFromClass([self class]);
		nibBundleOrNil = [JsBundleManager jsUtilityBundle];
	}
	if(self == [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
		
	}
	return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
	self.title = @"About";
	
	{
		_mLogoView.image = [JsBundleManager iconInBundleNamed:@"vgemv.png"];
		_mLogoView.companyName = @"骏视信息科技有限公司";
		
		NSMutableString * string = [NSMutableString stringWithFormat:@"JsUtilitySdkVersion:%@\n",[JsUtilitySdk sdkVersion]];
		[string appendFormat:@"AppVersion:%@\n",[self versionString]];
		_mLogoView.info = string;
		[_mLogoView setNeedsLayout];
	}
}

- (void)setVm:(JsAboutViewControllerVm *)vm {
	_vm = vm;
	[self updateVm];
}

- (void)renderVm {
	self.view.backgroundColor = _vm.backgroundColor;
	self.mLogoView.backgroundColor = _vm.logoViewColor;
}

-(void)updateVm {
	if(mi_updateCount == 0) {
		dispatch_async(dispatch_get_main_queue(), ^{
			[self renderVm];
			self->mi_updateCount=0;
		});
	}
	mi_updateCount++;
}

- (NSString *)getDemoVersion {
	NSDictionary * dic = [NSBundle mainBundle].infoDictionary;
	NSString * version = [dic valueForKey:@"CFBundleShortVersionString"];
	return version;
}

- (NSString *)getTargetEvnName {
	NSDictionary * dic_info = [NSBundle mainBundle].infoDictionary;
	NSDictionary * dic_targetConfig = [dic_info valueForKey:@"TargetConfig"];
	NSString * envName = [dic_targetConfig valueForKey:@"EnvName"];
	return envName;
}

- (NSString *)versionString {
	NSDictionary * dic_info = [[NSBundle mainBundle] infoDictionary];
	NSString * versionInfo = [NSString stringWithFormat:@"%@",dic_info[@"CFBundleShortVersionString"]];
	return versionInfo;
}

- (NSString *) envName {
	NSDictionary * dic_info = [[NSBundle mainBundle] infoDictionary];
	NSDictionary * dic_env = dic_info[@"TargetConfig"];
	return dic_env[@"EnvName"];
}

@end
